<?php

use App\Http\Controllers\Api\QuestionController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\TestController;
use App\Http\Controllers\Api\HistoryController;
use App\Http\Controllers\Api\SourceController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

$ApiControllerBasePath = "App\Http\Controllers\Api";


Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

/**
 * 需要token认知的接口组
 */
Route::middleware(['jwt.auth'])->group(function () {
    // 这里面放需要认证的接口
    // 如果出先有一些不需要验证的在apiResource 就可以使用except方法排除掉 index代表的别名 你可以通过php artisan route:list 查看
    // 然后在这个gruop外面重新定义一个路由来指向这个index
    //如下方的
    // Route::apiResource('v1/history', HistoryController::class)->except(['index']);

    /**
     * 历史记录接口
     */
    Route::apiResource('v1/history', HistoryController::class);

    /**
     * 考试
     */
    Route::prefix('/v1/exam')->group(function () {
        $ApiControllerBasePath = "App\Http\Controllers\Api";
        // 预约考试
        Route::post('/reservation/{id}', "$ApiControllerBasePath\ExamController@reservation");
        // 评分
        Route::post('/score/{id}', "$ApiControllerBasePath\ExamController@score");
        // 模拟考试
        // Route::post('/simulation/{id}', "$ApiControllerBasePath\ExamController@simulation");
    });

    /**
     * 消息
     */
    Route::prefix('/v1/message')->group(function () {
        $ApiControllerBasePath = "App\Http\Controllers\Api";
        // 添加消息
        Route::post('/add', "$ApiControllerBasePath\MessageController@add");
        // 获取消息
        Route::get('/{id}', "$ApiControllerBasePath\MessageController@get");
    });

    /**
     * 公告
     */
    Route::prefix('/v1/announcement')->group(function () {
        $ApiControllerBasePath = "App\Http\Controllers\Api";
        // 添加消息
        Route::post('/add', "$ApiControllerBasePath\AnnouncementController@add");
    });
});
// 添加 index 方法，这里不需要认证
// Route::get('v1/history', "$ApiControllerBasePath\HistoryController@index")->name('history.index');
// Route::middleware('jwt.auth')->apiResource('v1/history', HistoryController::class);

/**
 * 问题相关接口
 */
Route::apiResource('v1/question', QuestionController::class);

/**
 * 题源接口
 */
Route::apiResource('v1/source', SourceController::class);

/**
 * 用户接口
 */
Route::prefix('/v1/user')->group(function () {
    $ApiControllerBasePath = "App\Http\Controllers\Api";
    Route::post('/register', "$ApiControllerBasePath\UserController@register");
    Route::delete('/delete/{id}', "$ApiControllerBasePath\UserController@del");
    Route::delete('/physical_delete/{id}', "$ApiControllerBasePath\UserController@physicalDel");
    Route::put('/edit/{id}', "$ApiControllerBasePath\UserController@edit");
    Route::post('/login', "$ApiControllerBasePath\UserController@login");
    Route::get('/default', "$ApiControllerBasePath\UserController@default");
    Route::get('/avatar/{id}', "$ApiControllerBasePath\UserController@avatar");
    Route::post('/upload/{id}', "$ApiControllerBasePath\UserController@upload");
    Route::get('/token', "$ApiControllerBasePath\UserController@token");
    Route::get('/check', "$ApiControllerBasePath\UserController@check");
});
